package com.example.ks.util;


import java.sql.*;

public class DBUtil {
    private static final String URL = "jdbc:mysql://localhost:3306/cwfwdatabase";
    // 数据库用户名，根据实际情况修改
    private static final String USER = "root";
    // 数据库密码，根据实际情况修改
    private static final String PASSWORD = "123456";

    static {
        try {
            // 加载MySQL 8.x版本的驱动类
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

    public static void close(ResultSet rs, Statement stmt, Connection conn) {
        try {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}